<template>
  <el-dialog :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
      <el-form-item label="单号" prop="billId">
        <el-input v-model="dataForm.billId" placeholder="单号"></el-input>
      </el-form-item>
      <el-form-item label="销售单id" prop="saleId">
        <el-input v-model="dataForm.saleId" placeholder="销售单id"></el-input>
      </el-form-item>
      <el-form-item label="入库仓库id" prop="inStockId">
        <el-input v-model="dataForm.inStockId" placeholder="入库仓库id"></el-input>
      </el-form-item>
      <el-form-item label="出库仓库id" prop="outStockId">
        <el-input v-model="dataForm.outStockId" placeholder="出库仓库id"></el-input>
      </el-form-item>
      <el-form-item label="出库时间" prop="outStockTime">
        <el-input v-model="dataForm.outStockTime" placeholder="出库时间"></el-input>
      </el-form-item>
      <el-form-item label="商品id" prop="goodsId">
        <el-input v-model="dataForm.goodsId" placeholder="商品id"></el-input>
      </el-form-item>
      <el-form-item label="商品代码" prop="goodsCode">
        <el-input v-model="dataForm.goodsCode" placeholder="商品代码"></el-input>
      </el-form-item>
      <el-form-item label="商品展示名称" prop="goodsDisplayName">
        <el-input v-model="dataForm.goodsDisplayName" placeholder="商品展示名称"></el-input>
      </el-form-item>
      <el-form-item label="商品供应商id" prop="supplyId">
        <el-input v-model="dataForm.supplyId" placeholder="商品供应商id"></el-input>
      </el-form-item>
      <el-form-item label="商品类别id" prop="ctgId">
        <el-input v-model="dataForm.ctgId" placeholder="商品类别id"></el-input>
      </el-form-item>
      <el-form-item label="销售时具体商品类别id" prop="ctgSaleId">
        <el-input v-model="dataForm.ctgSaleId" placeholder="销售时具体商品类别id"></el-input>
      </el-form-item>
      <el-form-item label="商品描述" prop="goodsDescription">
        <el-input v-model="dataForm.goodsDescription" placeholder="商品描述"></el-input>
      </el-form-item>
      <el-form-item label="商品数量" prop="goodsQuantity">
        <el-input v-model="dataForm.goodsQuantity" placeholder="商品数量"></el-input>
      </el-form-item>
      <el-form-item label="商品是否订做类型(1-是,0否)" prop="goodsCustomizeType">
        <el-input v-model="dataForm.goodsCustomizeType" placeholder="商品是否订做类型(1-是,0否)"></el-input>
      </el-form-item>
      <el-form-item label="无库存标识(1-是,0-否)" prop="noStockFlag">
        <el-input v-model="dataForm.noStockFlag" placeholder="无库存标识(1-是,0-否)"></el-input>
      </el-form-item>
      <el-form-item label="商品是否为顾客自身物品(1-是,0-否)" prop="selfFlag">
        <el-input v-model="dataForm.selfFlag" placeholder="商品是否为顾客自身物品(1-是,0-否)"></el-input>
      </el-form-item>
      <el-form-item label="商品是否为赠品(1-是,-0-否)" prop="giftFlag">
        <el-input v-model="dataForm.giftFlag" placeholder="商品是否为赠品(1-是,-0-否)"></el-input>
      </el-form-item>
      <el-form-item label="是否退款(1-是,0-否,2-退部分)" prop="refundFlag">
        <el-input v-model="dataForm.refundFlag" placeholder="是否退款(1-是,0-否,2-退部分)"></el-input>
      </el-form-item>
      <el-form-item label="退货数量" prop="refundNumber">
        <el-input v-model="dataForm.refundNumber" placeholder="退货数量"></el-input>
      </el-form-item>
      <el-form-item label="部分退货后剩余数量" prop="refundAfterNumber">
        <el-input v-model="dataForm.refundAfterNumber" placeholder="部分退货后剩余数量"></el-input>
      </el-form-item>
      <el-form-item label="部分退货后剩余销售金额" prop="refundAfterMoney">
        <el-input v-model="dataForm.refundAfterMoney" placeholder="部分退货后剩余销售金额"></el-input>
      </el-form-item>
      <el-form-item label="部分退货后剩余销售积分" prop="refundAfterIntegral">
        <el-input v-model="dataForm.refundAfterIntegral" placeholder="部分退货后剩余销售积分"></el-input>
      </el-form-item>
      <el-form-item label="批次" prop="batch">
        <el-input v-model="dataForm.batch" placeholder="批次"></el-input>
      </el-form-item>
      <el-form-item label="失效日期" prop="invalidTime">
        <el-input v-model="dataForm.invalidTime" placeholder="失效日期"></el-input>
      </el-form-item>
      <el-form-item label="生产日期" prop="productionDate">
        <el-input v-model="dataForm.productionDate" placeholder="生产日期"></el-input>
      </el-form-item>
      <el-form-item label="注册证号" prop="registerNum">
        <el-input v-model="dataForm.registerNum" placeholder="注册证号"></el-input>
      </el-form-item>
      <el-form-item label="单价金额(销售时单价)" prop="price">
        <el-input v-model="dataForm.price" placeholder="单价金额(销售时单价)"></el-input>
      </el-form-item>
      <el-form-item label="商品原价金额" prop="originPrice">
        <el-input v-model="dataForm.originPrice" placeholder="商品原价金额"></el-input>
      </el-form-item>
      <el-form-item label="原价总金额" prop="originalPrice">
        <el-input v-model="dataForm.originalPrice" placeholder="原价总金额"></el-input>
      </el-form-item>
      <el-form-item label="折扣金额" prop="discountPrice">
        <el-input v-model="dataForm.discountPrice" placeholder="折扣金额"></el-input>
      </el-form-item>
      <el-form-item label="抹零金额" prop="removePrice">
        <el-input v-model="dataForm.removePrice" placeholder="抹零金额"></el-input>
      </el-form-item>
      <el-form-item label="积分和储值卡抵扣金额" prop="deductionPrice">
        <el-input v-model="dataForm.deductionPrice" placeholder="积分和储值卡抵扣金额"></el-input>
      </el-form-item>
      <el-form-item label="抵扣完金额" prop="deductionFinalPrice">
        <el-input v-model="dataForm.deductionFinalPrice" placeholder="抵扣完金额"></el-input>
      </el-form-item>
      <el-form-item label="应收金额" prop="receivablePrice">
        <el-input v-model="dataForm.receivablePrice" placeholder="应收金额"></el-input>
      </el-form-item>
      <el-form-item label="原来积分" prop="oldIntegral">
        <el-input v-model="dataForm.oldIntegral" placeholder="原来积分"></el-input>
      </el-form-item>
      <el-form-item label="商品所得积分" prop="integral">
        <el-input v-model="dataForm.integral" placeholder="商品所得积分"></el-input>
      </el-form-item>
      <el-form-item label="折扣类型(1-员工打折权限,2-打折卡打折)" prop="discountType">
        <el-input v-model="dataForm.discountType" placeholder="折扣类型(1-员工打折权限,2-打折卡打折)"></el-input>
      </el-form-item>
      <el-form-item label="折扣人员id" prop="discountUserId">
        <el-input v-model="dataForm.discountUserId" placeholder="折扣人员id"></el-input>
      </el-form-item>
      <el-form-item label="折扣率" prop="discountRate">
        <el-input v-model="dataForm.discountRate" placeholder="折扣率"></el-input>
      </el-form-item>
      <el-form-item label="出库标识(1-是,0否)" prop="outStorageFlag">
        <el-input v-model="dataForm.outStorageFlag" placeholder="出库标识(1-是,0否)"></el-input>
      </el-form-item>
      <el-form-item label="入库标识(1-是,0否)" prop="inStorageFlag">
        <el-input v-model="dataForm.inStorageFlag" placeholder="入库标识(1-是,0否)"></el-input>
      </el-form-item>
      <el-form-item label="镜片类型(L-左镜片,R-右镜片,F-镜架)" prop="glassFlag">
        <el-input v-model="dataForm.glassFlag" placeholder="镜片类型(L-左镜片,R-右镜片,F-镜架)"></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="memo">
        <el-input v-model="dataForm.memo" placeholder="备注"></el-input>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
      </el-form-item>
      <el-form-item label="修改时间" prop="updateTime">
        <el-input v-model="dataForm.updateTime" placeholder="修改时间"></el-input>
      </el-form-item>
      <el-form-item label="创建用户id" prop="createUser">
        <el-input v-model="dataForm.createUser" placeholder="创建用户id"></el-input>
      </el-form-item>
      <el-form-item label="修改用户id" prop="modifyUser">
        <el-input v-model="dataForm.modifyUser" placeholder="修改用户id"></el-input>
      </el-form-item>
      <el-form-item label="租户id" prop="tenantId">
        <el-input v-model="dataForm.tenantId" placeholder="租户id"></el-input>
      </el-form-item>
      <el-form-item label="组织id" prop="orgId">
        <el-input v-model="dataForm.orgId" placeholder="组织id"></el-input>
      </el-form-item>
      <el-form-item label="组织id" prop="unitId">
        <el-input v-model="dataForm.unitId" placeholder="组织id"></el-input>
      </el-form-item>
      <el-form-item label="逻辑删除(1-正常,-1已删除)" prop="delFlag">
        <el-input v-model="dataForm.delFlag" placeholder="逻辑删除(1-正常,-1已删除)"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" :loading="ischeck">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import {
    getEimsSaleRefundDetailObj,
    addEimsSaleRefundDetailObj,
    putEimsSaleRefundDetailObj
  } from '@/api/eims/salerefunddetail'

  export default {
    data() {
      return {
        visible: false,
        ischeck: false,
        dataForm: {
          id: 0,
          billId: '',
          saleId: '',
          inStockId: '',
          outStockId: '',
          outStockTime: '',
          goodsId: '',
          goodsCode: '',
          goodsDisplayName: '',
          supplyId: '',
          ctgId: '',
          ctgSaleId: '',
          goodsDescription: '',
          goodsQuantity: '',
          goodsCustomizeType: '',
          noStockFlag: '',
          selfFlag: '',
          giftFlag: '',
          refundFlag: '',
          refundNumber: '',
          refundAfterNumber: '',
          refundAfterMoney: '',
          refundAfterIntegral: '',
          batch: '',
          invalidTime: '',
          productionDate: '',
          registerNum: '',
          price: '',
          originPrice: '',
          originalPrice: '',
          discountPrice: '',
          removePrice: '',
          deductionPrice: '',
          deductionFinalPrice: '',
          receivablePrice: '',
          oldIntegral: '',
          integral: '',
          discountType: '',
          discountUserId: '',
          discountRate: '',
          outStorageFlag: '',
          inStorageFlag: '',
          glassFlag: '',
          memo: '',
          createTime: '',
          updateTime: '',
          createUser: '',
          modifyUser: '',
          tenantId: '',
          orgId: '',
          unitId: '',
          delFlag: ''
        },
        dataRule: {
          billId: [{required: true,message: '单号不能为空',trigger: 'blur'}],
          saleId: [{required: true,message: '销售单id不能为空',trigger: 'blur'}],
          inStockId: [{required: true,message: '入库仓库id不能为空',trigger: 'blur'}],
          outStockId: [{required: true,message: '出库仓库id不能为空',trigger: 'blur'}],
          outStockTime: [{required: true,message: '出库时间不能为空',trigger: 'blur'}],
          goodsId: [{required: true,message: '商品id不能为空',trigger: 'blur'}],
          goodsCode: [{required: true,message: '商品代码不能为空',trigger: 'blur'}],
          goodsDisplayName: [{required: true,message: '商品展示名称不能为空',trigger: 'blur'}],
          supplyId: [{required: true,message: '商品供应商id不能为空',trigger: 'blur'}],
          ctgId: [{required: true,message: '商品类别id不能为空',trigger: 'blur'}],
          ctgSaleId: [{required: true,message: '销售时具体商品类别id不能为空',trigger: 'blur'}],
          goodsDescription: [{required: true,message: '商品描述不能为空',trigger: 'blur'}],
          goodsQuantity: [{required: true,message: '商品数量不能为空',trigger: 'blur'}],
          goodsCustomizeType: [{required: true,message: '商品是否订做类型(1-是,0否)不能为空',trigger: 'blur'}],
          noStockFlag: [{required: true,message: '无库存标识(1-是,0-否)不能为空',trigger: 'blur'}],
          selfFlag: [{required: true,message: '商品是否为顾客自身物品(1-是,0-否)不能为空',trigger: 'blur'}],
          giftFlag: [{required: true,message: '商品是否为赠品(1-是,-0-否)不能为空',trigger: 'blur'}],
          refundFlag: [{required: true,message: '是否退款(1-是,0-否,2-退部分)不能为空',trigger: 'blur'}],
          refundNumber: [{required: true,message: '退货数量不能为空',trigger: 'blur'}],
          refundAfterNumber: [{required: true,message: '部分退货后剩余数量不能为空',trigger: 'blur'}],
          refundAfterMoney: [{required: true,message: '部分退货后剩余销售金额不能为空',trigger: 'blur'}],
          refundAfterIntegral: [{required: true,message: '部分退货后剩余销售积分不能为空',trigger: 'blur'}],
          batch: [{required: true,message: '批次不能为空',trigger: 'blur'}],
          invalidTime: [{required: true,message: '失效日期不能为空',trigger: 'blur'}],
          productionDate: [{required: true,message: '生产日期不能为空',trigger: 'blur'}],
          registerNum: [{required: true,message: '注册证号不能为空',trigger: 'blur'}],
          price: [{required: true,message: '单价金额(销售时单价)不能为空',trigger: 'blur'}],
          originPrice: [{required: true,message: '商品原价金额不能为空',trigger: 'blur'}],
          originalPrice: [{required: true,message: '原价总金额不能为空',trigger: 'blur'}],
          discountPrice: [{required: true,message: '折扣金额不能为空',trigger: 'blur'}],
          removePrice: [{required: true,message: '抹零金额不能为空',trigger: 'blur'}],
          deductionPrice: [{required: true,message: '积分和储值卡抵扣金额不能为空',trigger: 'blur'}],
          deductionFinalPrice: [{required: true,message: '抵扣完金额不能为空',trigger: 'blur'}],
          receivablePrice: [{required: true,message: '应收金额不能为空',trigger: 'blur'}],
          oldIntegral: [{ required: true, message: '原来积分不能为空', trigger: 'blur' }],
          integral: [{ required: true, message: '商品所得积分不能为空', trigger: 'blur' }],
          discountType: [{required: true,message: '折扣类型(1-员工打折权限,2-打折卡打折)不能为空',trigger: 'blur'}],
          discountUserId: [{required: true,message: '折扣人员id不能为空',trigger: 'blur'}],
          discountRate: [{required: true,message: '折扣率不能为空',trigger: 'blur'}],
          outStorageFlag: [{required: true,message: '出库标识(1-是,0否)不能为空',trigger: 'blur'}],
          inStorageFlag: [{required: true,message: '入库标识(1-是,0否)不能为空',trigger: 'blur'}],
          glassFlag: [{required: true,message: '镜片类型(L-左镜片,R-右镜片,F-镜架)不能为空',trigger: 'blur'}],
          memo: [{required: true,message: '备注不能为空',trigger: 'blur'}],
          createTime: [{required: true,message: '创建时间不能为空',trigger: 'blur'}],
          updateTime: [{required: true,message: '修改时间不能为空',trigger: 'blur'}],
          createUser: [{required: true,message: '创建用户id不能为空',trigger: 'blur'}],
          modifyUser: [{required: true,message: '修改用户id不能为空',trigger: 'blur'}],
          tenantId: [{required: true,message: '租户id不能为空',trigger: 'blur'}],
          orgId: [{required: true,message: '组织id不能为空',trigger: 'blur'}],
          unitId: [{required: true,message: '组织id不能为空',trigger: 'blur'}],
          delFlag: [{required: true,message: '逻辑删除(1-正常,-1已删除)不能为空',trigger: 'blur'}]
        }
      }
    },
    methods: {
      init(id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            getEimsSaleRefundDetailObj(this.dataForm.id).then(response => {
              if(response.data.code == '0'){
                this.dataForm = response.data.data
              }else{
                this.$message.error(response.data.msg)
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
        this.ischeck = true
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            if (this.dataForm.id) {
              putEimsSaleRefundDetailObj(this.dataForm).then(response => {
                if(response.data.code == '0'){
                  this.$message.success('修改成功')
                  this.visible = false
                  this.$emit('refreshDataList')
                }else{
                  this.$message.error(response.data.msg)
                }
                this.ischeck = false
              }).catch(() => {
                this.ischeck = false
              })
            } else {
              addEimsSaleRefundDetailObj(this.dataForm).then(response => {
                if(response.data.code == '0'){
                  this.$message.success('添加成功')
                  this.visible = false
                  this.$emit('refreshDataList')
                }else{
                  this.$message.error(response.data.msg)
                }
                this.ischeck = false
              }).catch(() => {
                this.ischeck = false
              })
            }
          }else{
            this.ischeck = false
          }
        })
      }
    }
  }
</script>
